package com.freedy.concurrent.OptimisticLock;

import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicStampedReference;

/**
 * @author Freedy
 * @date 2021/4/23 23:17
 */
public class AtomicStampedReferenceTest {
    public static void main(String[] args) {
        AtomicStampedReference<String> reference = new AtomicStampedReference<>("A",0);
        String prev = reference.getReference();
        int stamp = reference.getStamp();
        reference.compareAndSet(prev,"B",stamp,++stamp);
        System.out.println(reference.getReference());
    }
}
